#encoding:UTF-8
import re
import mylib
import pythonlibSB


def get_hot_link():
    
    try:
        results = []
        content = mylib.get_content('http://vtc.vn/')
        
        
        hot_10_link = []
        hot_10_content = pythonlibSB.s_string(content,'class="p1_tin"','div')
        reg = re.compile('(h1><a)(.*?)(href=")(.*?)(")')
        if reg.search(hot_10_content):
            url10 = reg.search(hot_10_content).group(4)
            url10 = url10 if url10.find('http://')!=-1 else ('http://vtc.vn'+url10)
            hot_10_link.append(url10)
        results.append(hot_10_link)
        
        
        hot_9_link = []
        hot_9_content = pythonlibSB.s_string(content,'class="p1_tinngang"','div')
        for i in re.finditer('(li><a)(.*?)(href=")(.*?)(")',hot_9_content):
            url9 = i.group(4) if i.group(4).find('http://')!=-1 \
                        else ('http://vtc.vn'+i.group(4))
            hot_9_link.append(url9)
        results.append(hot_9_link)
        
        hot_8_link = []
        hot_8_content = pythonlibSB.s_string(content,'id="hotnews_box"','div')
#        print hot_8_content
        for j in re.finditer('(<a)(.*?)(href=")(.*?)(")',hot_8_content):
            url8 = j.group(4)
            url8 = url8 if url8.find('http://')!=-1 else ('http://vtc.vn'+url8)
            hot_8_link.append(url8)
        results.append(hot_8_link)
        
        hot_7_link = []
        
            
        results.append(hot_7_link)
        
        return results
    except:
        return []
    
    
if __name__ == "__main__":
    results = get_hot_link()
    print results